package commLogger

import (
	"fmt"
	"gitee.com/fierce_wolf/go-fox-edge-common/commEnv"
	"time"
)

type cmdLineLoggerService struct {
}

func (e *cmdLineLoggerService) Error(value interface{}) {
	e.out("ERROR", value)
}

func (e *cmdLineLoggerService) Info(value interface{}) {
	e.out("INFO", value)
}

func (e *cmdLineLoggerService) Warn(value interface{}) {
	e.out("WARN", value)
}

func (e *cmdLineLoggerService) Debug(value interface{}) {
	e.out("DEBUG", value)
}

func (e *cmdLineLoggerService) out(level string, value interface{}) {
	data := e.build(level, value, time.Now().UnixMilli())

	fmt.Println(data)
}

func (e *cmdLineLoggerService) build(level string, value interface{}, timestamp int64) string {
	timeText := time.Unix(timestamp/1000, 0)
	return fmt.Sprintf("[%v:%v]-(%v)-[%v]: %v", commEnv.Service.ServiceType, commEnv.Service.ServiceName, timeText, level, value)
}
